package com.lln.cjcx.pojo.grade;

import com.lln.cjcx.util.CommonUtils;

import java.util.List;

/**
 * @author LiLinnan
 * @version 1.0
 * @date 2020/1/27 22:52
 */

public final class TermGrade extends yfdc.JavaBean implements Comparable<TermGrade>, java.io.Serializable {
	private static transient final long serialVersionUID = 0L;
	/**
	 * 学期名称
	 */
	private String termName;
	/**
	 * 成绩
	 */
	private List<Grade> grades;
	/**
	 * 学期号
	 */
	private String termId;

	public TermGrade(String termId, List<Grade> grades) {
		this.termId = termId;
		this.termName = CommonUtils.termName(termId);
		this.grades = grades;
	}

	public TermGrade(String termId, String termName, List<Grade> grades) {
		this.termId = termId;
		this.termName = termName;
		this.grades = grades;
	}

	public String getTermName() {
		return termName;
	}

	public void setTermName(String termName) {
		this.termName = termName;
	}

	public List<Grade> getGrades() {
		return grades;
	}

	public void setGrades(List<Grade> grades) {
		this.grades = grades;
	}


	public String getTermId() {
		return termId;
	}

	public void setTermId(String termId) {
		this.termId = termId;
	}

	@Override
	public String toString() {
		try {
			return yfdc.JavaBean.toString(this);
		} catch (Throwable ex) {
			ex.printStackTrace(System.out);
			return "TermGrade{" +
					"termName='" + termName + '\'' +
					", grades=" + grades +
					", termId='" + termId + '\'' +
					'}';
		}
	}

	@Override
	public final int compareTo(TermGrade termGrade) {
		String termId1 = this.termId;
		String termId2 = termGrade.getTermId();
		String[] termIds1 = termId1.split("-");
		String[] termIds2 = termId2.split("-");
		if (termIds1.length != 4 || termIds2.length != 4) {
			return 0;
		}
		try {
			int a = Integer.parseInt(termIds1[0]);
			int b = Integer.parseInt(termIds2[0]);
			int temp = Integer.compare(a, b) * -1;
			if (temp != 0) {
				return temp;
			}
			a = Integer.parseInt(termIds1[2]);
			b = Integer.parseInt(termIds2[2]);
			return Integer.compare(a, b) * -1;
		} catch (Throwable e) {
			e.printStackTrace(System.out);
			return 0;
		}
	}
}
